// This is the class functions to get the text and convert it to morse and 
// place it in a vector and display it.
// Copyright (C) 2008  Nicholas Hinkley <DarkLight.Programmer@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.


// To output/input 
#include <iostream>

// To use the vector
#include <vector>

#include "morse.h"


// To keep the code somewhat clean, somewhat.
using namespace std;


Morse::Morse() {

}

Morse::~Morse() {

}

// constructor to auto call the conveter on init.
Morse::Morse(vector<char> convertvector) {

   convertit(convertvector);

}

// Convert the text vector to Morse code.      
vector<char> Morse::convertit(vector<char> convertvector) {

   int i = 0;
   int nl = 0;
   vector<char> out;
   cout << endl;
   
   while( convertvector[i] != EOF ) {
   
      switch(convertvector[i]) {
      
         case 'A':
         case 'a':
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << ".- ";
            break;   
         case 'B':
         case 'b':
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << "-... "; 
            break;
         case 'C':
         case 'c':
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << "-.-. ";
            break;
         case 'D':
         case 'd':
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << "-.. ";
            break;
         case 'E':
         case 'e':
            out.push_back('.');
            out.push_back(' ');
            cout << ". ";
            break;
         case 'F':
         case 'f':
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << "..-. ";
            break;
         case 'G':
         case 'g':
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << "--. ";
            break;
         case 'H':
         case 'h':
            out.push_back('.');
            out.push_back('.');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << ".... ";
            break;
         case 'I':
         case 'i':
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << ".. ";
            break;
         case 'J':
         case 'j':
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << ".--- ";
            break;
         case 'K':
         case 'k':
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << "-.- ";
            break;
         case 'L':
         case 'l':
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << ".-.. ";
            break;
         case 'M':
         case 'm':
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << "-- ";
            break;
         case 'N':
         case 'n':
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << "-. ";
            break;
         case 'O':
         case 'o':
            out.push_back('-');
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << "--- ";
            break;
         case 'P':
         case 'p':
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << ".--. ";
            break;
         case 'Q':
         case 'q':
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << "--.- ";
            break;
         case 'R':
         case 'r':
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << ".-. ";
            break;
         case 'S':
         case 's':
            out.push_back('.');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << "... ";
            break;
         case 'T':
         case 't':
            out.push_back('-');
            out.push_back(' ');
            cout << "- ";
            break;
         case 'U':
         case 'u':
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << "..- ";
            break;
         case 'V':
         case 'v':
            out.push_back('.');
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << "...- ";
            break;
         case 'W':
         case 'w':
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << ".-- ";
            break;
         case 'X':
         case 'x':
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << "-..- ";
            break;
         case 'Y':
         case 'y':
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << "-.-- ";
            break;
         case 'Z':
         case 'z':
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << "--.. ";
            break;
         case '.':
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back(' ');
            cout << ".-.-.- ";
            break;
         case ',':
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back(' ');
            cout << "--..-- ";
            break;
         case '?':
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back(' ');
            cout << "..--.. ";
            break;
         case '/':
            out.push_back('-');
            out.push_back('.');
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << "-..-. ";
            break;
         case '@':
            out.push_back('.');
            out.push_back('-');
            out.push_back('-');
            out.push_back('.');
            out.push_back('-');
            out.push_back('.');
            out.push_back(' ');
            cout << ".--.-. ";
            break;
            
         case ' ':
            out.push_back(' ');
            out.push_back(' ');
            cout << "  ";
            nl++;
            if(nl >= 5) { 
               cout << "\n"; 
               nl = 0; 
               break;
            } else {
               break;
            }
            
         case EOF:
            out.push_back(EOF);
            cout << "EOF  ";
            break;
      
      }
      i++;
      if (out[i] == EOF) break;
   
   }

   cout << "\n\n";
   
   return out;

}
   
// End of file [with a new line at the end to make some compilers happy]
